//
//  TFCLogger.m
//  TFCCommon
//
//  Created by GaviniMacBook on 2018/3/16.
//  Copyright © 2018年 TFCoin. All rights reserved.
//

#import "TFCLogger.h"

#ifdef DEBUG
const DDLogLevel ddLogLevel = DDLogLevelAll;
#else
const DDLogLevel ddLogLevel = DDLogLevelOff;
#endif


@implementation TFCLogger

+ (void)load {
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
    [DDLog addLogger:[DDTTYLogger sharedInstance]];
    [[DDTTYLogger sharedInstance] setColorsEnabled:YES];
    
    [[DDTTYLogger sharedInstance] setForegroundColor:[UIColor redColor] backgroundColor:nil forFlag:DDLogFlagError];
    [[DDTTYLogger sharedInstance] setForegroundColor:[UIColor orangeColor] backgroundColor:nil forFlag:DDLogFlagWarning];
    [[DDTTYLogger sharedInstance] setForegroundColor:[UIColor blueColor] backgroundColor:nil forFlag:DDLogFlagInfo];
    [[DDTTYLogger sharedInstance] setForegroundColor:[UIColor purpleColor] backgroundColor:nil forFlag:DDLogFlagDebug];
    [[DDTTYLogger sharedInstance] setForegroundColor:[UIColor grayColor] backgroundColor:nil forFlag:DDLogFlagVerbose];
    
    DDFileLogger* fileLogger = [[DDFileLogger alloc] init];
    //fileLogger.rollingFrequency = 60 * 60 * 24; // 24 hour rolling
    fileLogger.maximumFileSize = 1024 * 1024;
    fileLogger.logFileManager.maximumNumberOfLogFiles = 10;
    [DDLog addLogger:fileLogger];
  });
}

+ (NSString*)logPath{
  NSArray* loggers = [DDLog allLoggers];
  for(id logger in loggers)
  {
    if([logger isKindOfClass:[DDFileLogger class]])
    {
      DDFileLogger* fileLogger = logger;
      return fileLogger.logFileManager.logsDirectory;
    }
  }
  
  return nil;
}

@end
